﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DBUtility;

public partial class BasicBase_SocLinke_SocLinkeAdd : System.Web.UI.Page
{
    String depID = "";
    
    protected void Page_Load(object sender, EventArgs e)
    {
       


    }
    public String GetDepartmentid()
    {
        SQLHelper db = new SQLHelper();
        String dep=db.GetDataTableBySqlStr("SELECT DepartmentID  FROM [Account_Users] where userid='" + Context.User.Identity.Name + "'").Rows[0][0].ToString();
        if (dep.Substring(4, 1) == "0")
            return dep.Substring(0, 4) + "000";
        else
            return dep;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        
        if (PublicFunction.GetRequstForm(Request, "sort01") != "" && PublicFunction.GetRequstForm(Request, "InfoName") != "")
        {
            if (!SocLinkeAdd())
                Response.Write("<script>alert('添加失败');history.back();</script>");
        }
        else
            Response.Write("<script>alert('信息输入不完整！');history.back();</script>");
    }

    bool SocLinkeAdd()
    {
        SQLHelper db = new SQLHelper();
        Guid SocLinkeID = Guid.NewGuid();
        if (db.SqlExec("INSERT INTO SocLinke(INFOID,InfoName,TelPhone,Address,Fax,mark,SortID,DepartmentID,userid,LinkPeople) VALUES('" + SocLinkeID + "','" + PublicFunction.GetRequstForm(Request, "InfoName") + "','" + PublicFunction.GetRequstForm(Request, "TelPhone") + "','" + PublicFunction.GetRequstForm(Request, "Address") + "','" + PublicFunction.GetRequstForm(Request, "Fax") + "','" + PublicFunction.GetRequstForm(Request, "mark") + "','" + PublicFunction.GetRequstForm(Request, "sort01") + "','" + PublicFunction.GetRequstForm(Request, "dep") + "','" + Context.User.Identity.Name + "','" + PublicFunction.GetRequstForm(Request, "LinkPeople") + "')"))
        {
            bool r=true;
            int i=1;
            while (PublicFunction.GetRequstForm(Request, "sSocProp"+i.ToString()) != "")
            {

                if (!db.SqlExec("INSERT INTO [SocProp]([SocPropName],[SocPropCount],[SocPropUnit],[SocLinkeID])VALUES('" + PublicFunction.GetRequstForm(Request, "sSocProp" + i.ToString()) + "','" + PublicFunction.GetRequstForm(Request, "nSocProp" + i.ToString()) + "','" + PublicFunction.GetRequstForm(Request, "dSocProp" + i.ToString()) + "','" + SocLinkeID + "')"))
                    r = false;
                i++;
            }
            return r;
        }
        return false;
    }
}
